package tw.com.controller;

import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.annotations.Parameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import tw.com.dao.SysCodeDAO;
import tw.com.dao.report08.CDIDAO;
import tw.com.dao.report09.Report09Dao;
import tw.com.service.SysCodeService;
import tw.com.service.SysCodeServiceImpl;
import tw.com.to.CDITO_09;
import tw.com.to.SysCodeTO;

/**
 * 
 * 
 * 
 * @author alexho
 * @date 2012/9/23
 * @version 1.0
 */
@Controller
@RequestMapping("/report09")
public class Report09Controller {
	private Log log = LogFactory.getLog(Report09Controller.class);

	@Autowired
	private Report09Dao dao09;

	@Autowired
	private SysCodeDAO sysCodeDao;

	@RequestMapping(value = "/find", method = RequestMethod.GET)
	public String find(Model model) {

		Map<String, String> productTypeMap = sysCodeDao.getProductType();
		Map<String, String> madeinMap = sysCodeDao.getMadeIn();

		model.addAttribute("productTypeMap", productTypeMap);
		model.addAttribute("madeinMap", madeinMap);

		return "report09View";
	}

	@RequestMapping(value = "/find", method = RequestMethod.POST)
	public String doFind(int step, String startDate, String surveyDate5_start,
			String surveyDate5_over, String finishForeverDate8_start,
			String finishForeverDate8_over, String cdiid, String custId,
			String productType, String newProduct, String oldProduct,
			String madein, String orgId, String finishDetetmineDate6,
			String determine, String salesId, String unusualType, Model model) {

		List<CDITO_09> cdiList = dao09.query(step, startDate,
				surveyDate5_start, surveyDate5_over, finishForeverDate8_start,
				finishForeverDate8_over, cdiid, custId, productType,
				newProduct, oldProduct, madein, orgId, finishDetetmineDate6,
				determine, salesId, unusualType);

		Map<String, String> productTypeMap = sysCodeDao.getProductType();
		Map<String, String> madeinMap = sysCodeDao.getMadeIn();
		Map<String, String> orgName = sysCodeDao.getOrgName();
		Map<String, String> unusualTypeMap = sysCodeDao.getUnusualType();
		Map<String, String> customerName = sysCodeDao.getCustomerName();

		model.addAttribute("productTypeMap", productTypeMap);
		model.addAttribute("madeinMap", madeinMap);
		model.addAttribute("orgName", orgName);
		model.addAttribute("unusualTypeMap", unusualTypeMap);
		model.addAttribute("cdiList", cdiList);
		model.addAttribute("customerName", customerName);
		model.addAttribute("post", "post");
		
		model.addAttribute("step",step );
		model.addAttribute("startDate", startDate);
		model.addAttribute("surveyDate5_start", surveyDate5_start);
		model.addAttribute("surveyDate5_over", surveyDate5_over);
		model.addAttribute("finishForeverDate8_start",finishForeverDate8_start );
		model.addAttribute("finishForeverDate8_over", finishForeverDate8_over);
		model.addAttribute("cdiid", cdiid);
		model.addAttribute("custId", custId);
		model.addAttribute("productType", productType);
		model.addAttribute("newProduct",newProduct );
		model.addAttribute("oldProduct", oldProduct);
		model.addAttribute("madein", madein);
		model.addAttribute("orgId", orgId);
		model.addAttribute("finishDetetmineDate6",finishDetetmineDate6 );
		model.addAttribute("determine", determine);
		model.addAttribute("salesId",salesId );
		model.addAttribute("unusualType",unusualType);

		return "report09View";
	}
}
